﻿using System;
using System.Reflection;
using AcceptanceTest.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AcceptanceTest.Framework.UnitTests
{
    
    
    /// <summary>
    ///This is a test class for MSTestStepsDefinitionTest and is intended
    ///to contain all MSTestStepsDefinitionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MSTestStepsDefinitionTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for MSTestStepsDefinition Constructor
        ///</summary>
        [TestMethod()]
        public void MSTestStepsDefinitionConstructorTest()
        {
            int n = 0;

            //string fileName = @"D:\Users\Public\My Projects\aat-codeplex\AcceptanceTestExcelAddIn\bin\Debug\AcceptanceTest.Framework.dll";
            string fileName = @"D:\Users\Public\My Projects\aat-codeplex\AcceptanceTest.PasswordSample\bin\Debug\AcceptanceTest.PasswordSample.dll";
            Assembly assembly = Assembly.LoadFile(fileName);

            foreach (var type in assembly.GetTypes())
            {
                foreach (var attr in type.GetCustomAttributes(true))
                {
                    Console.WriteLine(string.Format("{0}: {1}, {2}", type.Name, attr.ToString(), 
                        attr is StepDefinitionAttribute));

                    //if (attr.GetType().Name == "StepDefinitionAttribute")
                    //{
                    //    var name = ((StepDefinitionAttribute)attr).Name;
                    //}

                    if (attr is StepDefinitionAttribute)
                    {
                        n++;
                    }
                }
            }

            Assert.IsTrue(n>0);
        }
    }
}
